<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><s:if test="role.roleId==null"><s:text name="role.add.title"/></s:if><s:else><s:text name="role.edit.title"/></s:else></title>
	<%@ include file="/common/meta.jsp"%>
	<%@ include file="/common/common.jsp"%>
</head>
<body>
<div id="wrapper">
	<div class="curmb"><s:text name="your.site.position"/>:<a href="${ctx}/main.action"><s:text name="homepage"/></a><span>></span><s:text name="role.title"/></div>
	<div class="listtit"><p><span><strong><s:if test="role.roleId==null"><s:text name="role.add.title"/></s:if><s:else><s:text name="role.edit.title"/></s:else></strong></span></p></div>
	<div class="listadd">
		<s:form action="role-save" onsubmit="return chkform()">
		<s:hidden name="role.roleId" id="role.roleId"/>
		<table class="addgrid">
		<s:hidden name="orig" />
			<tr>
				<th><s:text name="role.roleName"/>:</th>
				<td><s:textfield name="role.roleName" id="role.roleName" required="true" requiredposition="right" cssClass="txtin" />
				<span id="roleName-Message" style="color: red;">*</span>
				</td>
			</tr>
			<tr>
				<th><s:text name="role.memo"/>:</th>
				<td><s:textarea name="role.memo"  cssClass="memoclass" id="lmemo" onkeydown="textareaMaxProc(this,255)" onkeyup="textareaMaxProc(this,255)" onchange="textareaMaxProc(this,255)" ></s:textarea>
				<span id="smessage" style="color: red;"></span>
				</td>
			</tr>
<c:if test='${orig =="edit" }'>
			<tr>
				<th><s:text name="role.createTime"/>:</th>
				<td><s:textfield name="role.createTime" cssClass="txtin" readonly="true" /></td>
			</tr>
			<tr>
				<th><s:text name="role.createLoginName"/>:</th>
				<td><s:textfield name="role.createLoginName" cssClass="txtin" readonly="true" /></td>
			</tr>
			<tr>
				<th><s:text name="role.createRealName"/>:</th>
				<td><s:textfield name="role.createRealName" cssClass="txtin" readonly="true"/></td>
			</tr>
			<tr>
				<th><s:text name="role.updateLoginName"/>:</th>
				<td><s:textfield name="role.updateLoginName" cssClass="txtin" readonly="true"/></td>
			</tr>
			<tr>
				<th><s:text name="role.updateRealName"/>:</th>
				<td><s:textfield name="role.updateRealName" cssClass="txtin" readonly="true"/></td>
			</tr>
			<tr>
				<th><s:text name="role.updateTime"/>:</th>
				<td><s:textfield name="role.updateTime" cssClass="txtin" readonly="true"/></td>
			</tr>
</c:if>
			<tr>
				<th>&nbsp;</th>
				<td>
				<s:submit id="role_input" value="%{getText('save')}" cssClass="btnlist2"/>
				<s:reset value="%{getText('reset')}" cssClass="btnlist2"/>
				<input type="button" value="<s:text name='return'/>" class="btnlist2" onclick="history.back()">
				</td>
			</tr>
		</table>
		</s:form>
	</div>
</div>

<script type="text/javascript" defer="defer">

	function chkform(){
		var roleName=  $("input[name=role.roleName]").val();
		if(roleName==''){
			$$.g("#roleName-Message").innerHTML = "请填写角色名称";
			return false;
		}else{
			$$.g("#roleName-Message").innerHTML = "";
		}
	}
	
	//角色名唯一性验证
	function checkRoleName(){
		var roleName=$('input[name=role.roleName]').val();
		if(roleName==""){
			return false;
		}
		var myDate=new Date();
		var obj = {"role.roleName":roleName};
		$.post("${ctx}/system/role-checkNameUnique.action",obj,function(data){
			if(data=="ok"){
				$("#role_input").attr("disabled",false);
			}else if(data=="no"){
				$("#role_input").attr("disabled",true);
			}
		}); 
	}
	var roleName_pass=false;
	$$.addEvent("#role.roleName","blur",function(){
			var myDate=new Date();
			var roleName=$('input[name=role.roleName]').val();
			if(roleName=='') {
				$$.g("#roleName-Message").innerHTML = "请填写角色名称";
				return false;
			}
			var roleId=$('input[name=role.roleId]').val();
			var obj={"role.roleName":roleName,"role.roleId":roleId};
			$.post("${ctx}/system/role-checkNameUnique.action",obj,function(data){
				if(data=="ok"){
					roleName_pass=true;
					if(roleName_pass){
						$("#role_input").attr("disabled",false);
					}
					$$.g("#roleName-Message").style.color = "#0f0"; 
					$$.g("#roleName-Message").innerHTML = "可用";
				}else if(data=="no"){
					roleName_pass=false;
					$("#role_input").attr("disabled",true);
					$$.g("#roleName-Message").style.color = "#f00"; 
					$$.g("#roleName-Message").innerHTML = "该角色已经注册，请登录";
				}
			}); 
	});
	
	
	/**
	 * 限制textarea输入字数
	 * 调用举例：textareaDisplayValidator($('#SMS_CONTENT'),20,'<s:text name="validator.SMS_CONTENT.onfocus"/>');
	 * @param textArea，输入文字内容的文本域对象
	 * @param total，最大输入字数
	 * @param message，输入字数超过最大限制的提示消息
	 */
	
	function textareaMaxProc(textArea, total)
	{
      var message="长度过长！";
	  var max;
	  max=total;
	  var val = $(textArea).val();
	  var len=0;
	  var result = "";
	  for (var i = 0; i < val.length; i++)   
      {  
          if (val.charCodeAt(i) >= 0x4e00 && val.charCodeAt(i) <= 0x9fa5){   
              len += 2;  
          }else if ((val.charCodeAt(i) >= 0xff00 && val.charCodeAt(i) <= 0xffef)  
                  || (val.charCodeAt(i) >= 0x3000 && val.charCodeAt(i) <= 0x303f)){  
              //全角ASCII、全角中英文标点、半宽片假名、半宽平假名、半宽韩文字母  
              //作为2个字符计算  
              len += 2;  
          }else {  
              len++;  
          }  
          if(len>max)
        	  break;
          result +=val.charAt(i);
      }  
	  if(len >= max)
	  {
		  $$.g("#smessage").innerHTML=message; 
		  $(textArea).val(result);
	  }else{
		  $$.g("#smessage").innerHTML=""; 
	  }
	}
	
</script>
</body>
</html>
